#include "stdio.h"
#include "unistd.h"
#include "sys/types.h"
#include "sys/stat.h"
#include "fcntl.h"
#include "stdlib.h"
#include "string.h"

#define beepon      1
#define beepoff     0



int main(int argc, char *argv[])
{
    int fd;
    int ret;
    char *filename;
    unsigned char databuf[1];
    

    if(argc != 3)
    {
        printf("error args\n");
        return -1;
    }

    filename = argv[1];

    fd = open(filename, O_RDWR);
    if(fd < 0)
    {
        printf("can't open file %s\r\n", argv[1]);
        return -1;
        
    }
    
    databuf[0] = atoi(argv[2]);	/* 要执行的操作：打开或关闭 */
    ret=write(fd, databuf, sizeof(databuf));

    if(ret < 0)
    {
        printf("write image file failed\r\n");
        close(fd);
        return -1;
    }
    printf("write succes.\r\n");

    ret=close(fd);
    if(ret<0){
        printf("close failed\r\n");
        return -1 ;
    }
    return 0;

}